package com.lemon.ai.socket.packets.spiritgame.model.main;

import java.util.List;

import com.lemon.ai.socket.packets.spiritgame.model.db.MetaData;
import com.lemon.ai.socket.packets.spiritgame.model.dto.Table;
import com.lemon.ai.socket.packets.spiritgame.model.generator.DaoClassPropertiesGenerator;
import com.lemon.ai.socket.packets.spiritgame.model.generator.DaoIfcGenerator;
import com.lemon.ai.socket.packets.spiritgame.model.generator.DaoImplGenerator;
import com.lemon.ai.socket.packets.spiritgame.model.generator.DbUtilsGenerator;
import com.lemon.ai.socket.packets.spiritgame.model.generator.DbcpPropertiesGenerator;
import com.lemon.ai.socket.packets.spiritgame.model.generator.DtoGenerator;
import com.lemon.ai.socket.packets.spiritgame.model.generator.FactoryGenerator;
import com.lemon.ai.socket.packets.spiritgame.model.utils.FileUtils;

public class Main {

	private static DaoIfcGenerator daoIfcGenerator = new DaoIfcGenerator();
	private static DaoImplGenerator daoImplGenerator = new DaoImplGenerator();
	private static DtoGenerator dtoGenerator = new DtoGenerator();
	private static FactoryGenerator factoryGenerator = new FactoryGenerator();
	private static DbUtilsGenerator jdbcUtilsGenerator = new DbUtilsGenerator();
	private static DbcpPropertiesGenerator dbcpGenerator = new DbcpPropertiesGenerator();
	private static DaoClassPropertiesGenerator daoClassGenerator = new DaoClassPropertiesGenerator();
	private static FileUtils fu = new FileUtils();

	public static void main(String[] args) {
		
		System.setProperty("file.encoding", "UTF-8");
		
		MetaData meta = MetaData.getInstance();
		List<Table> tables = meta.getTables();
		fu.write(factoryGenerator.generateFileName(), 
				factoryGenerator.generate(tables));
		fu.write(jdbcUtilsGenerator.generateFileName(), 
				jdbcUtilsGenerator.generate());
		fu.write(daoClassGenerator.generateDaoClassName(),
				daoClassGenerator.generate(tables));
		fu.write(dbcpGenerator.generateDbcpConfigName(),
				dbcpGenerator.generate());
		for (int i = 0; i < tables.size(); i++) {
			Table t = tables.get(i);
			fu.write(daoIfcGenerator.generateFileName(t), 
					daoIfcGenerator.generate(t));
			fu.write(daoImplGenerator.generateFileName(t), 
					daoImplGenerator.generate(t));
			fu.write(dtoGenerator.generateFileName(t), 
					dtoGenerator.generate(t));
		}
	}

}
